package 消费者与生产者模式练习.Test01;

import java.util.List;

public class Consumption implements Runnable {
    private List<Integer> list;
    public Consumption(List<Integer> list) {
        this.list = list;
    }
    @Override
    public void run() {
        while (true){
            synchronized (list) {
                if (list.size() == 0) {
                    try {
                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                for (int a = 0; a < 2; a++) {
                    Integer i = list.remove(a);
                    System.out.println(i++);
                    try {

                        list.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    list.notify();
                }
            }
        }
    }
}
